home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / SpaceballViewer / MySlider.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  7.0 KB  |  214 lines

  1. /*
  2.  * Copyright (c) 1990-94 Silicon Graphics, Inc.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that the name of Silicon Graphics may not be used in any advertising or
  7.  * publicity relating to the software without the specific, prior written
  8.  * permission of Silicon Graphics.
  9.  *
  10.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  11.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  12.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  13.  *
  14.  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  15.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
  17.  * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  */
  20. //  -*- C++ -*-
  21.  
  22. /*
  23.  * Copyright (C) 1990-93   Silicon Graphics, Inc.
  24.  *
  25.  _______________________________________________________________________
  26.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  27.  |
  28.  |   $Revision: 1.1012 $
  29.  |
  30.  |   Description:
  31.  |    This file contains the MySlider class which is a GL slider within
  32.  |  a GLX widget. The slider contains a text label to its left, and a
  33.  |  user editable text field to the right which displays the numeric value
  34.  |  of the slider. There are methods to disable either of these text fields.
  35.  |
  36.  |   Classes:
  37.  |    MySlider
  38.  |    
  39.  |   Author(s)    : Alain Dumesny
  40.  |
  41.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  42.  _______________________________________________________________________
  43.  */
  44.  
  45. #ifndef  _SO_XT_SLIDER_
  46. #define  _SO_XT_SLIDER_
  47.  
  48. #include <Inventor/misc/SoCallbackList.h>
  49. #include <Inventor/Xt/SoXtGLWidget.h>
  50.  
  51.  
  52. class MyFloatCallbackList;
  53. class SoXtMouse;
  54.  
  55. // callback function prototypes
  56. typedef void MySliderCB(void *userData, float val);
  57.  
  58. //////////////////////////////////////////////////////////////////////////////
  59. //
  60. //  Class: MySlider
  61. //
  62. //    This is the basic slider type, which lets you set the slider value and
  63. //  register callbacks when the slider is being moved (either as soon as the
  64. //  slider changes values, or when the slider has stopped moving (mouse up)).
  65. //
  66. //////////////////////////////////////////////////////////////////////////////
  67.  
  68. // C-api: prefix=SoXtSldr
  69. class MySlider : public SoXtGLWidget {
  70.   public:
  71.     
  72.     // constructor/destructor
  73.     MySlider(
  74.     Widget parent = NULL,
  75.     const char *name = NULL, 
  76.     SbBool buildInsideParent = TRUE);
  77.     ~MySlider();
  78.     
  79.     //
  80.     // Those routines are used to specify the slider value (which is automatically
  81.     // reflected in the slider) and get the current value.
  82.     //
  83.     // NOTE: setValue() will call valueChanged callbacks if the value differs.
  84.     //
  85.     // NOTE: currently only values [0.0 , 1.0] are supported
  86.     //
  87.     void    setValue(float v);
  88.     float    getValue() const        { return value; }
  89.     
  90.     //
  91.     // Specifies the label string which appears before the slider. A NULL 
  92.     // string will remove the label altogether. (default behavior)
  93.     //
  94.     void        setLabel(const char *newlabel);
  95.     const char    *getLabel() const            { return labelStr; }
  96.     
  97.     //
  98.     // Display a numeric value in a text field to the right of the slider
  99.     // which can be edited to change the value of the slider.
  100.     // Default is TRUE (display the numeric value).
  101.     //
  102.     void    setNumericFieldVisible(SbBool b);
  103.     SbBool    isNumericFieldVisible() const    { return numberVisible; }
  104.     
  105.     //
  106.     // Those routines are used to register callbacks for the different slider
  107.     // actions.
  108.     //
  109.     // NOTE: the start and finish callbacks are only to signal when the mouse
  110.     // goes down and up. No valid callback data is passed (0.0 passed).
  111.     //
  112.     // C-api: name=addStartCB
  113.     void    addStartCallback(
  114.             MySliderCB *f,
  115.             void *userData = NULL);
  116.     // C-api: name=addValueChangedCB
  117.     void    addValueChangedCallback(
  118.             MySliderCB *f,
  119.             void *userData = NULL);
  120.     // C-api: name=addFinishCB
  121.     void    addFinishCallback(
  122.             MySliderCB *f,
  123.             void *userData = NULL);
  124.  
  125.     // C-api: name=removeStartCB
  126.     void    removeStartCallback(
  127.             MySliderCB *f,
  128.             void *userData = NULL);
  129.     // C-api: name=removeValueChangedCB
  130.     void    removeValueChangedCallback(
  131.             MySliderCB *f,
  132.             void *userData = NULL);
  133.     // C-api: name=removeFinishCB
  134.     void    removeFinishCallback(
  135.             MySliderCB *f,
  136.             void *userData = NULL);
  137.             
  138.     // true while the value is changing interactively
  139.     SbBool  isInteractive()                     { return interactive; }
  140.     
  141.     // sets/gets the size of the actual slider, excluding the label and
  142.     // text field widget sizes which are fixed in size. 
  143.     //
  144.     // This is the prefered behavior since it allows a user to align
  145.     // multiple sliders (same size) regardless of the text label size
  146.     // (which are usually different).
  147.     //
  148.     // NOTE: this is different from most widgets, which do resize their
  149.     // container widgets. This functionality can still be achieved using
  150.     // the setSize() and getSize() methods.
  151.     //
  152.     void        setSliderSize(const SbVec2s &size);
  153.     SbVec2s        getSliderSize();
  154.     
  155.   protected:  
  156.  
  157.     // This constructor takes a boolean whether to build the widget now.
  158.     // Subclasses can pass FALSE, then call MySlider::buildWidget()
  159.     // when they are ready for it to be built.
  160.     SoEXTENDER
  161.     MySlider(
  162.     Widget parent,
  163.     const char *name, 
  164.     SbBool buildInsideParent, 
  165.     SbBool buildNow);
  166.  
  167.     // redefine these to do slider specific things
  168.     virtual void    redraw();
  169.     virtual void    processEvent(XAnyEvent *anyevent);
  170.     virtual void    sizeChanged(const SbVec2s &newSize);
  171.  
  172.     Widget        buildWidget(Widget parent);
  173.     
  174.     //
  175.     // this is the routine subclasses would redefine to change the look of
  176.     // the actual slider top region, which defaults to grey with a thin white marker.
  177.     //
  178.     virtual void    drawSliderTopRegion();
  179.  
  180.     // slider top region area (used by subclasses to do their own
  181.     // drawings in there).
  182.     short    slx1, sly1, slx2, sly2;
  183.     short    thumx1, thumy1, thumx2, thumy2;
  184.     
  185.  private:
  186.     Widget        mgrWidget, numberWidget, sliderWidget, labelWidget;
  187.     SbBool        numberVisible;    // whether numeric field is visible
  188.     char            *labelStr;        // label preceeding slider
  189.     SbVec2s        sliderSize;        // size of the 'widget' and 'shell'
  190.     SoXtMouse        *mouse;
  191.     
  192.     // slider local variables (slider value, thum position)
  193.     float        value;
  194.     short        position, posdiff;
  195.     
  196.     // build routines
  197.     void            doLabelLayout();
  198.     void        doNumberLayout();
  199.     
  200.     // callback variables
  201.     MyFloatCallbackList  *startCallbacks;
  202.     MyFloatCallbackList  *changedCallbacks;
  203.     MyFloatCallbackList  *finishCallbacks;
  204.     SbBool          interactive;
  205.     
  206.     // text field vars and callbacks
  207.     static void        textFieldCB(Widget, MySlider *, XtPointer);
  208.  
  209.     // this is called by both constructors
  210.     void constructorCommon(SbBool buildNow);
  211. };
  212.  
  213. #endif  /* _SO_XT_SLIDER_ */
  214.